package com.hooware.dao;

import com.hooware.domain.Orders;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IOrdersDao {

    /**
     * 查询所有订单
     * @return
     */
    @Select("select orders.id, orders.ordernum, product.productname,product.productprice, orders.ordertime, orders.orderstatus from orders inner join product on orders.productid = product.id")
    @Results({
            @Result(column = "productname", property = "product.productName"),
            @Result(column = "productprice", property = "product.productPrice")
    })
    List<Orders> findAll();

    /**
     * 根据id查询orders
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    @Results({
            @Result(one = @One(select = "com.hooware.dao.IProductDao.findById"), column = "PRODUCTID", property = "product"),
            @Result(one = @One(select = "com.hooware.dao.IMemberDao.findById"), column = "MEMBERID", property = "member"),
            @Result(many = @Many(select = "com.hooware.dao.ITravellerDao.findById"), column = "id", property = "travellers")
    })
    Orders findById(String id);
}
